return ret;
}
-static gboolean
-resolve_rev (OstreeRepo *self,
- const char *rev,
- gboolean allow_noent,
- char **sha256,
- GError **error)
+gboolean
+ostree_repo_resolve_rev (OstreeRepo *self,
+ const char *rev,
+ gboolean allow_noent,
+ char **sha256,
+ GError **error)
{
OstreeRepoPrivate *priv = GET_PRIVATE (self);
gboolean ret = FALSE;
char *tmp2 = NULL;
char *ret_rev = NULL;
GFile *child = NULL;
+ GFile *origindir = NULL;
char *child_path = NULL;
GError *temp_error = NULL;
GVariant *commit = NULL;
+ g_return_val_if_fail (rev != NULL, FALSE);
+
if (strlen (rev) == 0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid empty rev");
goto out;
}
+ else if (strstr (rev, "..") != NULL)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid rev %s", rev);
+ goto out;
+ }
else if (strlen (rev) == 64)
{
ret_rev = g_strdup (rev);
tmp = g_strdup (rev);
tmp[strlen(tmp) - 1] = '\0';
- if (!resolve_rev (self, tmp, allow_noent, &tmp2, error))
+ if (!ostree_repo_resolve_rev (self, tmp, allow_noent, &tmp2, error))
goto out;
if (!ostree_repo_load_variant_checked (self, OSTREE_SERIALIZED_COMMIT_VARIANT, tmp2, &commit, error))
}
else
{
- child = g_file_get_child (priv->local_heads_dir, rev);
- child_path = g_file_get_path (child);
+ const char *slash = strchr (rev, '/');
+ if (slash != NULL && (slash == rev || !*(slash+1)))
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid rev %s", rev);
+ goto out;
+ }
+ else if (slash == NULL)
+ {
+ child = g_file_get_child (priv->local_heads_dir, rev);
+ child_path = g_file_get_path (child);
+ }
+ else
+ {
+ const char *rest = slash + 1;
+
+ if (strchr (rest, '/'))
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid rev %s", rev);
+ goto out;
+ }
+
+ child = g_file_get_child (priv->remote_heads_dir, rev);
+ child_path = g_file_get_path (child);
+
+ }
if (!ot_util_gfile_load_contents_utf8 (child, NULL, &ret_rev, NULL, &temp_error))
{
if (allow_noent && g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
g_free (tmp);
g_free (tmp2);
g_clear_object (&child);
+ g_clear_object (&origindir);
g_free (child_path);
g_free (ret_rev);
return ret;
}
-gboolean
-ostree_repo_resolve_rev (OstreeRepo *self,
- const char *rev,
- char **sha256,
- GError **error)
-{
- g_return_val_if_fail (rev != NULL, FALSE);
- return resolve_rev (self, rev, FALSE, sha256, error);
-}
-
static gboolean
write_checksum_file (GFile *parentdir,
const char *name,
if (!import_root (self, base, &root, error))
goto out;
- if (!resolve_rev (self, parent, TRUE, ¤t_head, error))
+ if (!ostree_repo_resolve_rev (self, parent, TRUE, ¤t_head, error))
goto out;
in = (GUnixInputStream*)g_unix_input_stream_new (fd, FALSE);
goto out;
}
- if (!resolve_rev (self, rev, FALSE, &resolved, error))
+ if (!ostree_repo_resolve_rev (self, rev, FALSE, &resolved, error))
goto out;
root = (OstreeRepoFile*)_ostree_repo_file_new_root (self, resolved);
GFile *ret_root = NULL;
char *resolved_rev = NULL;
- if (!resolve_rev (self, rev, FALSE, &resolved_rev, error))
+ if (!ostree_repo_resolve_rev (self, rev, FALSE, &resolved_rev, error))
goto out;
ret_root = _ostree_repo_file_new_root (self, resolved_rev);
char *baseurl = NULL;
char *refpath = NULL;
char *temppath = NULL;
+ char *remote_ref = NULL;
+ char *original_rev = NULL;
GKeyFile *config = NULL;
SoupURI *base_uri = NULL;
SoupURI *target_uri = NULL;
remote = argv[1];
branch = argv[2];
+ remote_ref = g_strdup_printf ("%s/%s", remote, branch);
+
+ if (!ostree_repo_resolve_rev (repo, remote_ref, TRUE, &original_rev, error))
+ goto out;
+
config = ostree_repo_get_config (repo);
key = g_strdup_printf ("remote \"%s\"", remote);
goto out;
g_strchomp (rev);
- if (!ostree_validate_checksum_string (rev, error))
- goto out;
-
- if (!store_commit_recurse (repo, soup, base_uri, rev, error))
- goto out;
-
- if (!ostree_repo_write_ref (repo, FALSE, branch, rev, error))
- goto out;
+ if (original_rev && strcmp (rev, original_rev) == 0)
+ {
+ g_print ("No changes in %s\n", remote_ref);
+ }
+ else
+ {
+ if (!ostree_validate_checksum_string (rev, error))
+ goto out;
+
+ if (!store_commit_recurse (repo, soup, base_uri, rev, error))
+ goto out;
+
+ if (!ostree_repo_write_ref (repo, remote, branch, rev, error))
+ goto out;
+
+ g_print ("remote %s is now %s\n", remote_ref, rev);
+ }
ret = TRUE;
out:
g_free (temppath);
g_free (key);
g_free (rev);
+ g_free (remote_ref);
+ g_free (original_rev);
g_free (baseurl);
g_free (refpath);
g_free (remote_branch_ref_path);